var t = require("./@babel/runtime/helpers/interopRequireDefault")(require("./@babel/runtime/helpers/defineProperty")), e = wx.getSystemInfoSync(), n = e.windowWidth, i = e.windowHeight, a = 1.05, o = .7;

Page({
    $$scrollTimer: null,
    $$inputValue: "",
    $$displayText: "请输入弹幕",
    data: {
        isIpx: getApp().globalData.isIpx,
        showMenu: !0,
        showInput: !1,
        pageHeight: 0,
        inputTextArray: [],
        displayCss: {
            transitionDuration: 0,
            practicalHeight: 0
        },
        fontColorIndex: 0,
        fontColorList: [ "#FFFFFF", "#FF0000", "#FF1177", "#FF00FF", "#00FF00", "#0000FF", "#FFFF00", "#00FFFF", "#65318E", "#1E50A2", "#006E54" ],
        backgroundIndex: 0,
        backgroundList: [ "#000000", "#65318E", "#1E50A2", "#C9171E", "#FFFFFF", "#006E54", "#E6B422", "#96514D", "#6E7955", "#EB6EA5" ],
        fontSizeIndex: 0,
        fontSizeList: [ 240, 300, 380, 500, 780 ],
        speedIndex: 0,
        speedList: [ 2, 1.4, 1, .6 ],
        defaultInputValue: ""
    },
    onLoad: function(t) {
        this.setData({
            pageHeight: Math.floor(750 * i / n)
        }), this.setDefaultParameter(t), this.runScroll();
    },
    onUnload: function() {
        this.stopScroll();
    },
    setDefaultParameter: function(t) {
        var e = t.displayText, n = t.fontSizeIndex, i = void 0 === n ? 0 : n, a = t.fontColorIndex, o = void 0 === a ? 0 : a, s = t.backgroundIndex, r = void 0 === s ? 0 : s, u = t.speedIndex, l = void 0 === u ? 0 : u;
        this.setData({
            fontSizeIndex: Number(i),
            fontColorIndex: Number(o),
            backgroundIndex: Number(r),
            speedIndex: Number(l)
        }), this.$$displayText = e || "请输入弹幕";
    },
    runScroll: function() {
        var t = this;
        this.setInputTextArray();
        var e = this.data.pageHeight + 800;
        this.data.inputTextArray.forEach(function(t) {
            return e += t.fontHeight;
        });
        var i = Math.ceil(e * this.data.speedList[this.data.speedIndex]), a = Math.ceil(e * n / 750);
        this.scroll(i, a), this.$$scrollTimer = setInterval(function() {
            t.scroll(i, a);
        }, i);
    },
    scroll: function(t, e) {
        var n = this;
        this.setData({
            displayCss: {
                transitionDuration: 0,
                practicalHeight: 0
            }
        }), setTimeout(function() {
            n.setData({
                displayCss: {
                    transitionDuration: t,
                    practicalHeight: e
                }
            });
        }, 300);
    },
    stopScroll: function() {
        this.$$scrollTimer && (clearInterval(this.$$scrollTimer), this.$$scrollTimer = null), 
        this.setData({
            displayCss: {
                transitionDuration: 0,
                practicalHeight: 0
            },
            inputTextArray: []
        });
    },

    backToHome:function(){
      wx.switchTab({
        url: '/pages/tabbar/index/index',
      })
    },
    setInputTextArray: function() {
        var t = this;
        this.setData({
            inputTextArray: this.$$displayText.split("").map(function(e) {
                return {
                    text: e,
                    fontHeight: t.setFontHeight(t.judgeText(e))
                };
            })
        });
    },
    setFontHeight: function(t) {
        var e = this.data, n = e.fontSizeIndex, i = e.fontSizeList, s = o, r = a;
        return Math.floor((t ? s : r) * i[n]);
    },
    onChangeScroll: function() {
        this.stopScroll(), this.runScroll();
    },
    onSetFontSize: function() {
        this.updateBarrage("fontSize"), this.onChangeScroll();
    },
    onSetFontColor: function() {
        this.updateBarrage("fontColor");
    },
    onSetBackgroundColor: function() {
        this.updateBarrage("background");
    },
    onSetSpeed: function() {
        this.updateBarrage("speed"), this.onChangeScroll();
    },
    onSendText: function() {
        var t = this;
        this.setData({
            defaultInputValue: this.$$inputValue || "",
            showInput: !1
        }), t.$$displayText = t.$$inputValue || "请输入弹幕", t.onChangeScroll();
    },
    onKeyInput: function(t) {
        this.$$inputValue = t.detail.value;
    },
    onShowInput: function() {
        this.setData({
            showInput: !0
        });
    },
    updateBarrage: function(e) {
        var n = "".concat(e, "Index");
        this.setData((0, t.default)({}, n, this.foreachFileIndex(this.data[n], this.data["".concat(e, "List")])));
    },
    onShowMenu: function() {
        this.data.showInput ? this.setData({
            showInput: !1
        }) : this.setData({
            showMenu: !this.data.showMenu
        });
    },
    onShareAppMessage: function() {
        var t = {
            displayText: this.$$displayText || "请输入弹幕",
            fontSizeIndex: this.data.fontSizeIndex || 0,
            fontColorIndex: this.data.fontColorIndex || 0,
            backgroundIndex: this.data.backgroundIndex || 0,
            speedIndex: this.data.speedIndex || 0
        };
        return {
            title: "分享的标题",
            path: "/page/index/index?".concat(this.urlObjToParameters(t))
        };
    },
    urlObjToParameters: function(t) {
        return Object.keys(t).map(function(e) {
            return "".concat(e, "=").concat(t[e]);
        }).join("&");
    },
    foreachFileIndex: function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0;
        return t === (arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : []).length - 1 ? 0 : t + 1;
    },
    judgeText: function(t) {
        return /^[A-Za-z0-9]*$/.test(t);
    },
    onChangeEvent: function(t) {
        this[t.detail]();
    }
});